package com.hdwx.weike.controllers;

import com.hdwx.weike.beans.User;
import com.hdwx.weike.dao.UserDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by hdwx on 2016/12/23.
 */
@WebServlet(urlPatterns = "/register.do")
public class RegisterController extends BaseController {
    @Override
    public void todo(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("utf-8");
        UserDao dao = new UserDao();
        User user = new User();//创建一个用户对象存储用户数据
        //读取请求的参数值
        String check = req.getParameter("check");
        String name = req.getParameter("name");
        String account = req.getParameter("account");
        String pwd = req.getParameter("password1");
        String sex = req.getParameter("sex");
        String tel = req.getParameter("tel");
        String email = req.getParameter("email");
        String work = req.getParameter("work");
        String city = req.getParameter("city");
        String area = req.getParameter("area");
        String school = req.getParameter("school");
        //设置用户信息
        user.setName(name);
        user.setAccount(account);
        user.setPwd(pwd);
        user.setSex(sex);
        user.setTel(tel);
        user.setEmail(email);
        user.setWork(work);
        user.setCity(city);
        user.setArea(area);
        user.setSchool(school);
        boolean b = dao.register(user);
        if (b) {
            System.out.println("用户信息注册成功！");
                resp.sendRedirect("registersuccess.jsp");
        }


    }
}
